<div class="panel label10-form">
    <h3>短信发送条件</h3>

    <form action="{:AddonU('SMS/call_sms_save')}" method="post">
        <ul>
            <if condition="$isSuperAdmin">
                <li><label>租户ID：</label><select name="siteID" title="请选择租户"></select></li>
                <else/>
                <li style="display: none;"><input type="hidden" name="siteID" value="{$loginData.siteID}"/></li>
            </if>
            <li>
                <label>短信服务器：</label>
                <select name="serverID" title="请选择短信服务器" required></select>
            </li>
            <li>
                <label>分机号：</label>
                <select name="agentID" title="请选择座席工号"></select>
            </li>
            <li><label></label>
                <textarea cols="30" rows="2" name="extensions" placeholder="分机号" required>{$data.extensions}</textarea></li>
            <li>
                <label>分机外呼时长(>=秒)：</label>
                <input type="text" name="extensionDuration" placeholder="请输入分机外呼时长" value="{$data.extensionDuration}"/>
            </li>
            <li>
                <label>短信内容：</label>
                <textarea cols="30" rows="2" name="message" placeholder="请输入短信内容">{$data.message}</textarea>
                <span></span>
            </li>
            <li>
                <label>短信签名：</label>
                <input type="text" name="sign" placeholder="请输入短信签名" value="{$data.sign}" readonly="readonly"/><!--鑫优轩-->
            </li>
            <li>
                <label>状态：</label>
                <input type="radio" name="state" value="1" checked="checked" required/>启用
                <input type="radio" name="state" value="0" required/>停用
            </li>
            <li>
                <label>&nbsp;</label>
                <input type="submit" value="保存"/><input type="button" value="关闭" class="btn-close-dialog"/></li>
        </ul>
        <input type='hidden' value='{$data.id}' name='id'/>
        <input type='hidden' value='extension' name='exTags'/>
        <input type='hidden' value='{$show}' name='show'/></form>
</div>
<script>
    $('input[name="state"][value="{$data.state}"]').prop('checked', true);
    ajax_load_options('select[name="siteID"]', '?s=XCall/Admin/get_admin_json.html', '选择租户', '{$data.siteID}', '', afterSiteID);
    afterSiteID();
    function afterSiteID() {
        var val = $('select[name="siteID"]').val();
        if (!val) {
            val = '{$loginData.siteID}';
        }
        ajax_load_options('select[name="agentID"]', '?s=XCall/Extension/get_extension_json/siteID/' + val + '.html', '选择座席工号');
        ajax_load_options('select[name="serverID"]', '?s=XCall/SMS/get_server_json/siteID/' + val + '.html', '选择短信服务器', '{$data.serverID}');
    }
    $('select[name="siteID"]').change(function () {
        afterSiteID();
    })
    $('select[name="agentID"]').change(function () {
        var $this = $(this);
        var $extends = $('textarea[name="extensions"]');
        var values = $extends.val();
        var val = $this.val();
        if (values.length > 2 && (',' + values + ',').indexOf(',' + val + ',') > -1) {
            return;
        }
        values = values + ',' + val;
        if (values[0] == ',') {
            values = values.substring(1);
        }
        $extends.val(values);
    })
    $('textarea[name="message"],input[name="sign"]').bind('blur keypress change', function () {
        var i = $('textarea[name="message"]').val().length + $('input[name="sign"]').val().length;
        $('#char-count').text(i);
    })
</script>